package com.zdy.state;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by 逸足天涯
 * on 3/9/2020.
 */
public class TestSleep2 {
    //模拟倒计时10，9
    public static void tenDown(){
        int num = 10;
        while(true){
            try {
                Thread.sleep(1000);
                System.out.println(num--);
                if (num <= 0){break;}
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Date startDate = new Date(System.currentTimeMillis());
        while(true){
            try {
                Thread.sleep(1000);
                System.out.println(new SimpleDateFormat("hh:mm:ss").format(startDate));
                //更新当前时间
                startDate = new Date(System.currentTimeMillis());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }
}
